/*
 * @Author: your name
 * @Date: 2022-03-28 13:35:37
 * @LastEditTime: 2022-03-28 20:22:06
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \blog_web\src\store\modules\follow.js
 */

// 导入本地存储的函数
import db from '@/util/localstorage'
// 导入用户的关注接口
import { getFollowList } from '@/api/follow.js'
const state = () => ({
  // 用户的关注数组
  follows: []
})
const getters = {}
const mutations = {
  // 设置关注表
  setFollows(state, follows) {
    db.save('follows', follows)
    state.follows = follows
  },
  // 从关注表中删除一个元素
  deleteFollow(state, index) {
    state.follows.splice(index, 1)
  }
}
const actions = {
  // 异步获取关注列表
  async getList({ commit }, { id }) {
    let res = await getFollowList({
      id
    })
    commit('setFollows', res.result)
  }
}
export default {
  namespaced: true,
  getters,
  state,
  mutations,
  actions
}
